<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <%
        String bathPath = request.getContextPath();
        pageContext.setAttribute("bathPath", bathPath);
    %>
    <meta charset="UTF-8">
    <title>人员排班</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="${bathPath}/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${bathPath}/css/common.css">
    <link rel="stylesheet" href="${bathPath}/css/formSelects-v4.css">
    <link rel="stylesheet" href="${bathPath}/css/timeSlot.css">
    <link rel="stylesheet" href="${bathPath}/css/holiday.css">
    <style>
        #classSettingMask, #addTimeMask, #personTotalSetting, #temporary {
            display: none;
        }
        .demoTable .layui-input.w150 {
            width: 150px;
        }

        .addTimeSlot .layui-form-label {
            width: 169px;
        }

        .personTotalSetting .layui-form-label {
            width: 155px;
        }

        .addTimeSlot .layui-form-item .layui-input-inline {
            width: 212px;
        }

        .arrange {
            display: inline-block;
            margin-bottom: 10px;
            margin-right: 10px;
            width: 80%;
        }

        .layui-input-block {
            margin-left: 155px;
        }

        .demo-class {
            overflow-y: auto;
        }

        .layui-table-page {
            position: fixed;
        }
    </style>
</head>
<body>
<div class="holiday">
    <div class="layui-form demoTable">
        <div class="layui-inline">
            <label class="layui-form-label">部门</label>
            <div class="layui-input-inline">
                <select type="text" id="depId" name="depId" lay-verify="required" lay-filter="business"
                        autocomplete="off" class="layui-input">
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">员工</label>
            <div class="layui-input-inline">
                <select type="text" id="userName" xm-select="userName" xm-select-show-count="1" xm-select-direction="down" lay-filter="userName" name="userName" lay-verify="required" autocomplete="off"
                        class="layui-input">
                </select>
            </div>
        </div>

        <%--        <div class="layui-inline">--%>
        <%--            <label class="layui-form-label">默认班次</label>--%>
        <%--            <div class="layui-input-inline">--%>
        <%--                <select name="defaltClass" id="defaltClass">--%>
        <%--                    <option value=""></option>--%>
        <%--                    <option value="0">正常班</option>--%>
        <%--                </select>--%>
        <%--            </div>--%>
        <%--        </div>--%>

        <div class="layui-inline">
            <label class="layui-form-label">起止时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input w150" name="test1" id="test1" placeholder="请选择开始时间"
                       autocomplete="off">
            </div>
            <span class="separator">-</span>
            <div class="layui-input-inline">
                <input type="text" class="layui-input w150" name="test2" id="test2" placeholder="请选择结束时间">
            </div>
        </div>
        <div class="layui-inline" style="margin-left: 20px;">
            <button class="layui-btn layui-btn-normal w92" data-type="reload">查询</button>
            <button class="layui-btn layui-btn-normal" id="personArrange" data-type="personArrange">人员排班</button>
        </div>
    </div>
    <%--    <div class="layui-btn-group ml-54 demoTable">--%>
    <%--        <button class="layui-btn layui-btn-normal" data-type="arrangeWork">临时排班</button>--%>
    <%--    </div>--%>

    <%--    <div class="layui-btn-group ml-54 demoTable">--%>
    <%--        <button class="layui-btn layui-btn-normal" data-type="classSetting">班次设置</button>--%>
    <%--    </div>--%>

    <%--    <div class="layui-btn-group ml-54 demoTable">--%>
    <%--        <button class="layui-btn layui-btn-normal" data-type="personArrange">人员排班</button>--%>
    <%--    </div>--%>
<%--    <div class="layui-btn-group ml-54 demoTable">--%>
<%--        <button class="layui-btn layui-btn-normal" id="personArrange" data-type="personArrange">人员排班</button>--%>
<%--    </div>--%>
    <table class="layui-table" lay-data="{ url:'${bathPath}/userOfRun/selectAll.action', page: false,id:'testReload',height: 'full-76'}"
           lay-filter="test" style="overflow:auto;">
        <thead>
        <tr>
            <%--            <th lay-data="{checkbox:true, fixed:'left'}" rowspan="2"></th>--%>
            <th lay-data="{field:'userId', width:80,align:'center',fixed:'left'}" rowspan="2">编号</th>
            <th lay-data="{field:'userName', width:86,align:'center'}" rowspan="2">姓名</th>
            <th lay-data="{align:'center'}" colspan="4">当前班次</th>
            <th lay-data="{align:'center'}" colspan="4">班次定义</th>
            <th lay-data="{minWidth: 500, align: 'center', toolbar: '#barDemo'}" rowspan="2">操作</th>
        </tr>
        <tr>
            <th lay-data="{field:'numRunName', width:75,align:'center'}">名称</th>
            <th lay-data="{field:'startTime', width:170,align:'center', templet: function (data) {
                return formatTime(data.startTime);
            }}">开始时间
            </th>
            <th lay-data="{field:'endTime', width:170,align:'center', templet: function (data) {
                return formatTime(data.endTime);
            }}">结束时间
            </th>
            <th lay-data="{field:'isArrangeWork', width:92,align:'center',templet: function (data) {
                            return formatterArrangeWork(data.tmepStartTime);
                        }}">临时排班
            </th>

            <th lay-data="{field:'defClassstartTime', width:170,align:'center', templet: function (data) {
                return formatTime(data.numRunTime);
            }}">开始时间
            </th>
            <th lay-data="{field:'defClassEndTime', width:170,align:'center', templet: function (data) {
                return formatTime(data.numEndTime);
            }}">结束时间
            </th>
            <th lay-data="{field:'cycle', width:70,align:'center'}">周期</th>
            <th lay-data="{field:'units', width:70,align:'center',templet: function (data) {
                            return formatterCycleType(data.units);
                        }}">单位
            </th>
        </tr>
        </thead>
    </table>
</div>

<script type="text/html" id="barDemo">
    <%--    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="addTime">增加时段</a>--%>

    <a class="layui-btn layui-btn-xs" lay-event="checkTime">查看时段</a>
    <a class="layui-btn layui-btn-xs" lay-event="classSetting">班次设置</a>
    <%--    <a class="layui-btn layui-btn-xs" lay-event="personArrange">人员排班</a>--%>
    <a class="layui-btn layui-btn-xs" lay-event="arrangeWork">临时排班</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delTime">清除时段</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancelTime">取消临时排班</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delCurrentClass">删除当前班次</a>
</script>

<div id="chart-wrapper" style="display: none;">
    <div class="chartContent" id="chartContent" style="width:90%;margin:0 auto;height:700px;overflow-y: auto;"></div>
</div>


<!--增加时段弹出层-->
<%--<div id="addTimeMask">--%>
<%--    <form class="layui-form time-slot addTimeSlot" action="#" lay-filter="example2">--%>
<%--        <input type="hidden" id="numRunId" name="numRunId">--%>
<%--        <div class="layui-form-item">--%>
<%--            <label class="layui-form-label">选择所属班次时段</label>--%>
<%--            <div class="layui-input-inline">--%>
<%--                <select name="classTimeSlot" id="classTimeSlot" lay-verify="required">--%>

<%--                </select>--%>
<%--            </div>--%>
<%--        </div>--%>
<%--        <div class="layui-form-item">--%>
<%--            <label class="layui-form-label">选择要添加该时间段的日期</label>--%>
<%--            <div class="layui-input-inline">--%>
<%--                <select name="dateTimeSlot" xm-select="selectId" xm-select-show-count="5" xm-select-direction="down"--%>
<%--                        name="dateTimeSlot" id="dateTimeSlot" lay-verify="required"></select>--%>
<%--            </div>--%>
<%--        </div>--%>

<%--        <div class="layui-form-item">--%>
<%--            <label class="layui-form-label">该时段是否记为加班</label>--%>
<%--            <div class="layui-input-inline">--%>
<%--                <input type="radio" name="isAddWork" value="0" title="否" checked>--%>
<%--                <input type="radio" name="isAddWork" value="1" title="是">--%>
<%--            </div>--%>
<%--        </div>--%>

<%--        <div class="layui-form-item">--%>
<%--            <label class="layui-form-label">记加班分钟数</label>--%>
<%--            <div class="layui-input-inline">--%>
<%--                <input type="text" name="addWorkTime" class="layui-input" id="addWorkTime" lay-verify="required|number"--%>
<%--                       placeholder="请输入分钟数">--%>
<%--            </div>--%>
<%--        </div>--%>

<%--        <div class="layui-form-item">--%>
<%--            <div class="layui-input-block">--%>
<%--                <button lay-submit class="layui-btn layui-btn-normal" lay-filter="formTest2" id="confirm2">确定</button>--%>
<%--                <button type="button" class="layui-btn layui-btn-primary cancel-layer">取消</button>--%>
<%--            </div>--%>
<%--        </div>--%>

<%--    </form>--%>
<%--</div>--%>
<%--部门班次弹出层--%>
<div id="classSettingMask">
    <form class="layui-form time-slot classSetting" action="#" lay-filter="example3">
        <div class="layui-form-item">
            <label class="layui-form-label">默认班次</label>
            <div class="layui-input-inline">
                <select name="numRunId" id="numRunId2" lay-verify="required"></select>
            </div>
        </div>
        <%--        <div class="layui-form-item">--%>
        <%--            <label class="layui-form-label">可排班班次</label>--%>
        <%--            <div class="layui-input-inline" id="canArrangeClass"></div>--%>
        <%--        </div>--%>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button lay-submit class="layui-btn layui-btn-normal" lay-filter="formTest3">确定</button>
                <button type="button" class="layui-btn layui-btn-primary cancel-layer">取消</button>
            </div>
        </div>
    </form>
</div>

<%--人员统计设置--%>
<div id="personTotalSetting">
    <form class="layui-form time-slot personTotalSetting" id="myForm" action="#" lay-filter="example4">
        <input type="hidden" name="userId" id="userId">
        <div class="layui-form-item">
            <label class="layui-form-label">签到</label>
            <div class="layui-input-inline">
                <input type="radio" name="checkIn" value="0" title="根据相应时段判断" checked>
                <input type="radio" name="checkIn" value="1" title="上班必须签到">
                <input type="radio" name="checkIn" value="2" title="上班不用签到">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">签退</label>
            <div class="layui-input-inline">
                <input type="radio" name="checkOut" value="0" title="根据相应时段判断" checked>
                <input type="radio" name="checkOut" value="1" title="下班必须签退">
                <input type="radio" name="checkOut" value="2" title="下班不用签退">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">进行智能排班</label>
            <div class="layui-input-inline">
                <input type="radio" name="autoSchPlan" lay-filter="autoSchPlan" value="1" title="是" checked>
                <input type="radio" name="autoSchPlan" lay-filter="autoSchPlan" value="0" title="否">
            </div>
        </div>

        <div class="layui-form-item" id="autoSchplan">
            <label class="layui-form-label">最少的智能排班时间</label>
            <div class="layui-input-inline">
                <input type="text" name="autoDays" class="layui-input arrange" id="autoDays"
                       lay-verify="required|number"
                       placeholder="请输入天数">天<input type="text" name="autoHours" class="layui-input arrange"
                                                   id="autoHours" lay-verify="required|number"
                                                   placeholder="请输入小时数">小时
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">计算考勤</label>
            <div class="layui-input-inline">
                <input type="radio" name="isCount" value="1" title="是" checked>
                <input type="radio" name="isCount" value="0" title="否">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">计算加班</label>
            <div class="layui-input-inline">
                <input type="radio" name="isOverTime" value="1" title="是" checked>
                <input type="radio" name="isOverTime" value="0" title="否">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">节假日有效</label>
            <div class="layui-input-inline">
                <input type="radio" name="isHolidays" value="1" title="是" checked>
                <input type="radio" name="isHolidays" value="0" title="否">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">加班需要经过登记或审核</label>
            <div class="layui-input-inline">
                <input type="radio" name="isExamine" value="1" title="是" checked>
                <input type="radio" name="isExamine" value="0" title="否">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">选择班次</label>
            <div class="layui-input-inline">
                <select name="numRunId" id="selectClass" lay-verify="required"></select>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button lay-submit class="layui-btn layui-btn-normal" lay-filter="formTest4">确定</button>
                <button type="button" class="layui-btn layui-btn-primary cancel-layer">取消</button>
            </div>
        </div>
    </form>
</div>

<div id="temporary">
    <form class="layui-form time-slot addTimeSlot" action="#" lay-filter="example2">
        <input type="hidden" id="temporaryNumRunId" name="numRunId">
        <input type="hidden" id="userIdTemporary" name="userId">
        <div class="layui-form-item">
            <label class="layui-form-label">选择所属班次时段</label>
            <div class="layui-input-inline">
                <select name="classTimeSlot" id="temporaryClassTimeSlot" lay-verify="required">

                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">选择要添加该时间段的日期</label>
            <div class="layui-input-inline">
                <select name="startDays" xm-select="selectId" xm-select-show-count="5" xm-select-direction="down"
                        id="dateTimeSlot" lay-verify="required"></select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">该时段是否记为加班</label>
            <div class="layui-input-inline">
                <input type="radio" name="isAddWork" value="0" title="否" lay-filter="isAddWork">
                <input type="radio" name="isAddWork" value="1" title="是" lay-filter="isAddWork" checked>
            </div>
        </div>

        <div class="layui-form-item" id="addWorkTimeWrap">
            <label class="layui-form-label">记加班分钟数</label>
            <div class="layui-input-inline">
                <input type="text" name="addWorkTime" class="layui-input" id="addWorkTime" lay-verify="required|number" placeholder="请输入分钟数">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button lay-submit class="layui-btn layui-btn-normal" lay-filter="formTest5">确定</button>
                <button type="button" class="layui-btn layui-btn-primary cancel-layer">取消</button>
            </div>
        </div>

    </form>
</div>


<script src="${bathPath}/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="${bathPath}/js/jquery-1.9.1.min.js"></script>
<script src="${bathPath}/js/formSelects-v4.min.js"></script>
<script type="text/javascript" src="${bathPath}/js/common.js"></script>
<script src="${bathPath}/js/echarts.js" type="text/javascript"></script>
<script>
    var layerIndex = null;
    var myChart = null;
    $(function () {
        initLayUI();
        initDept();
        initNumRunName();
    })


    function initLayUI() {
        layui.use(['form', 'laydate', 'layer', 'table'], function () {
            var form = layui.form;
            var laydate = layui.laydate;
            var table = layui.table;
            var layer = layui.layer;
            var formSelects = layui.formSelects;
            //日期时间选择器
            laydate.render({
                elem: '#test1'
                , type: 'datetime'
                ,trigger: 'click'
            });

            //日期时间选择器
            laydate.render({
                elem: '#test2'
                , type: 'datetime'
                ,trigger: 'click'
            });


            //监听工具条
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                if (obj.event === 'addTime') {
                    runAddTimeEvent(data);
                } else if (obj.event === 'delTime') {
                    $.ajax({
                        type: "POST",
                        async:false,
                        data: {numRunId:data.numRunId,deilType:1},
                        dataType:'json',
                        contentType:"application/x-www-form-urlencoded",
                        url: "${bathPath}/numRunDeil/findNumRunDeilBean.action",
                        success: function (res) {

                            if (res && res.length > 0) {
                                layer.confirm('真的清除时段吗', function (index) {
                                    //清除时段逻辑
                                    var dataJson = {};
                                    dataJson.id = data.numRunId;
                                    $.ajax({
                                        type: 'POST',
                                        data: dataJson,
                                        contentType: "application/x-www-form-urlencoded",
                                        url: '${bathPath}/numRunDeil/delete.action',
                                        success: function (data) {
                                            layer.close(index);
                                            if (data == 'SUCCESS') {
                                                layer.alert('时段已删除!',{
                                                    icon:1,
                                                    title:'提示'
                                                })
                                                //执行重载
                                                table.reload('testReload', {
                                                    where: {
                                                        depId: '',
                                                        userId:'',
                                                        startTime: '',
                                                        endTime: ''
                                                    }
                                                    // , page: {
                                                    //     curr: 1
                                                    // }
                                                });
                                            }else{
                                                layer.alert('删除失败!',{
                                                    icon:2,
                                                    title:'提示'
                                                })
                                            }
                                        }
                                    })
                                });
                            }else{
                                layer.alert('暂无时段!',{
                                    icon:5,
                                    title:'提示'
                                })
                            }
                        }
                    });
                } else if(obj.event === 'cancelTime') {
                    if(data.tmepStartTime){
                        //取消临时排班
                        $.ajax({
                            type: "POST",
                            async:false,
                            data: {userId:data.userId,numRunId:data.numRunId},
                            dataType:'json',
                            contentType:"application/x-www-form-urlencoded",
                            url: "${bathPath}/userTempSch/delete.action",
                            success: function (msg) {
                                if (msg == 'SUCCESS') {
                                    layer.alert('临时排班已取消!',{
                                        icon:1,
                                        title:'提示'
                                    })
                                    //执行重载
                                    table.reload('testReload', {
                                        where: {
                                            depId: '',
                                            userId:'',
                                            startTime: '',
                                            endTime: ''
                                        }
                                        // , page: {
                                        //     curr: 1
                                        // }
                                    });
                                }else{
                                    layer.alert('取消临时排班失败!',{
                                        icon:2,
                                        title:'提示'
                                    })
                                }
                            }
                        });
                    }else{
                        layer.alert('暂无临时排班!',{
                            icon:5,
                            title:'提示'
                        })
                    }
                } else if (obj.event === 'checkTime') {
                    var startTime = $('#test1').val();
                    var endTime = $('#test2').val();
                    if (!startTime || !endTime) {
                        layer.alert('请选择查看时段的起止时间');
                        return;
                    }
                    layerIndex = layer.open({
                        type: 1
                        , title: '班次时间段' //不显示标题栏
                        // ,class:'full-125'
                        , area: '90%;'
                        , shade: 0.8
                        , skin: 'demo-class'
                        , id: 'LAY_layuipro4' //设定一个id，防止重复弹出
                        // ,btn: ['确定', '取消']
                        // ,btnAlign: 'c'
                        , moveType: 1 //拖拽模式，0或者1
                        , content: $('#chart-wrapper')
                        , success: function (layero, index) {
                            form.render();
                            initEcharts(data);
                        }
                    });
                } else if (obj.event === 'delCurrentClass'){
                    // 删除当前班次
                    $.ajax({
                        type: "POST",
                        async:false,
                        data: {userId:data.userId,numRunId:data.numRunId,runSort:data.runSort},
                        dataType:'json',
                        contentType:"application/x-www-form-urlencoded",
                        url: "${bathPath}/userOfRun/delete.action",
                        success: function (msg) {
                            if (msg == 'SUCCESS') {
                                layer.alert('删除当前班次成功!',{
                                    icon:1,
                                    title:'提示'
                                })
                                //执行重载
                                table.reload('testReload', {
                                    where: {
                                        depId: '',
                                        userId:'',
                                        startTime: '',
                                        endTime: ''
                                    }
                                    // , page: {
                                    //     curr: 1
                                    // }
                                });
                            }else{
                                layer.alert('删除当前班次失败!',{
                                    icon:2,
                                    title:'提示'
                                })
                            }
                        }
                    });
                } else if (obj.event === 'classSetting') {
                    active.classSetting(data);
                } else if (obj.event === 'personArrange') {
                    active.personArrange(data);
                } else if (obj.event === 'arrangeWork') {
                    active.arrangeWork(data);
                }
            });

            //点击添加班次时段中的是否加班单选按钮
            form.on('radio(isAddWork)', function(data){
                if(data.value == 1){
                    $("#addWorkTimeWrap").show();
                    $("#addWorkTime").attr("lay-verify","required|number");
                }else{
                    $("#addWorkTimeWrap").hide();
                    $("#addWorkTime").removeAttr("lay-verify");
                }
            });


            form.on('select(business)', function (data) {
                //获取部门的ID通过异步查询子集
                var depId = $(this).attr("lay-value");
                $.ajax({
                    type: "POST",
                    async:false,
                    data: {depId:depId},
                    dataType:'json',
                    contentType:"application/x-www-form-urlencoded",
                    url: "${bathPath}/userInfo/selectUserName.action",
                    success: function (msg) {
                        var html = "";
                        html += "<option value=''>" + '请选择员工' + "</option>";
                        for (var i = 0; i < msg.length; i++) {
                            html += "<option value='" + msg[i].userID + "'>" + msg[i].userName + "</option>";
                        }
                        $("#userName").html(html);
                        form.render('select');
                        formSelects.render('userName');
                    }
                });
            });

            //提交增加时段表单
            form.on('submit(formTest2)', function (data) {
                var dataJson = data.field;
                // 增加时段
                dataJson.numRunId = $('#numRunId').val();
                dataJson.schClassId = data.field.classTimeSlot;
                dataJson.endDays = dataJson.startDays = data.field.dateTimeSlot;
                $.ajax({
                    type: 'POST',
                    data: dataJson,
                    contentType: "application/x-www-form-urlencoded",
                    url: '${bathPath}/numRunDeil/insert.action',
                    success: function (data) {
                        if (data == 'SUCCESS') {
                            layer.close(layerIndex);
                            table.reload('testReload', {
                                where: {}
                                // , page: {
                                //     curr: 1
                                // }
                            });
                        }
                    }
                })
                return false;
            })


            //提交临时排班班次时段表单
            form.on('submit(formTest5)', function (data) {
                var dataJson = Object.assign({}, data.field);
                //临时排班添加时段
                dataJson.numRunId = $('#temporaryNumRunId').val();
                dataJson.schClassId = data.field.classTimeSlot;
                dataJson.startTime = $('#test1').val();
                dataJson.endTime = $('#test2').val();
                dataJson.userId = $('#userIdTemporary').val();
                delete dataJson.classTimeSlot;

                var startTimeStr = formSelects.value('selectId', 'name');

                dataJson.startTimeStr = startTimeStr.toString();
                dataJson.deilType = 2;
                $.ajax({
                    type: 'POST',
                    data: dataJson,
                    contentType: "application/x-www-form-urlencoded",
                    url: '${bathPath}/userTempSch/insert.action',
                    success: function (data) {
                        if (data == 'SUCCESS') {
                            layer.close(layerIndex);
                            table.reload('testReload', {
                                where: {}
                                // , page: {
                                //     curr: 1
                                // }
                            });
                        }
                    }
                })
                return false;
            })
            //班次设置
            form.on('submit(formTest3)', function (data) {
                var depId = $('#depId').val();
                var dataJson = data.field;
                dataJson.depId = depId;
                $.ajax({
                    type: 'POST',
                    data: dataJson,
                    contentType: "application/x-www-form-urlencoded",
                    url: '${bathPath}/depNumRun/insert.action',
                    success: function (data) {
                        if (data == 'SUCCESS') {
                            layer.close(layerIndex);
                            table.reload('testReload', {
                                where: {}
                                // , page: {
                                //     curr: 1
                                // }
                            });
                        }
                    }
                })
                return false;
            })


            form.on('radio(autoSchPlan)', function(data){
//			    console.log(data.value); //被点击的radio的value值

                if(data.value == 1){
                    $("#autoSchplan").show();
                    $("#autoDays,#autoHours").attr("lay-verify","required|number");
                }else{
                    $("#autoSchplan").hide();
                    $("#autoDays,#autoHours").removeAttr("lay-verify");
                }
            });


            //人员排班提交
            form.on('submit(formTest4)', function (data) {
                var dataJson = data.field;
                var startTime = $('#test1').val();
                var endTime = $('#test2').val();
                //获取起止时间范围内选中的日期
                getSelectDate(startTime,endTime,dataJson,table);

                return false;
            })


            var $ = layui.$, active = {
                arrangeWork: function (data) { //获取选中数据
                    var userName = data.userName;
                    var startTime = $('#test1').val();
                    var endTime = $('#test2').val();
                    if (!startTime || !endTime) {
                        layer.alert('请选择临时排班的起止时间');
                        return;
                    }
                    layer.confirm('对选择的人员:' + userName + '从' + startTime + '到' + endTime + '期间进行临时排班吗?', function (index) {
                        layer.close(index);
                        layer.confirm('是否选择其他时段?', function (secondIndex) {
                            // 显示添加班次时段弹出层
                            layer.close(secondIndex);
                            runAddTimeTemporary(data);
                        }, function () {
                            //点击取消触发的事件
                        })

                    });
                },
                //班次设置
                classSetting: function (data) {
                    var depId = $('#depId').val();
                    if (!depId) {
                        layer.alert("<div class='alertBox_text'>请先选择一个部门!</div>");
                        return false;
                    }
                    layerIndex = layer.open({
                        type: 1
                        , title: '部门班次设置' //不显示标题栏
                        , area: '350px;'
                        , shade: 0.8
                        , id: 'LAY_layuipro6' //设定一个id，防止重复弹出
                        // ,btn: ['确定', '取消']
                        // ,btnAlign: 'c'
                        , moveType: 1 //拖拽模式，0或者1
                        , content: $('#classSettingMask')
                        , success: function (layero, index) {
                            var dataJson = {
                                depId: depId
                            }
                            //查询所选部门已设置的班次
                            $.ajax({
                                type: 'POST',
                                data: dataJson,
                                contentType: "application/x-www-form-urlencoded",
                                url: '${bathPath}/depNumRun/select.action',
                                success: function (data) {
                                    // form.val('example3', {
                                    //     numRunId:data.numRunId
                                    // })
                                    form.render();
                                }
                            })
                        }
                    });
                },
                // 人员安排
                personArrange: function () {
                    var startTime = $('#test1').val();
                    var endTime = $('#test2').val();
                    var userId = formSelects.value('userName', 'valStr');
                    if(!userId){
                        layer.alert('请选择要排班的人员');
                        return;
                    }
                    if (!startTime || !endTime) {
                        layer.alert('请选择人员排班的起止时间');
                        return;
                    }
                    var userName = document.getElementById('userName');//获取select的dom
                    var index = userName.selectedIndex;//获取选中的index
                    var userNameLabel = userName.options[index].text; //获取标签值
                    // var userName = data.userName;
                    // var userId = data.userId;
                   $('#myForm')[0].reset();
                    layerIndex = layer.open({
                        type: 1
                        , title: '人员统计设置(' + userNameLabel + ')' //不显示标题栏
                        , area: '450px;'
                        , shade: 0.8
                        , skin: 'demo-class'
                        , id: 'LAY_layuipro6' //设定一个id，防止重复弹出
                        // ,btn: ['确定', '取消']
                        // ,btnAlign: 'c'
                        , moveType: 1 //拖拽模式，0或者1
                        , content: $('#personTotalSetting')
                        , success: function (layero, index) {
                            // initDateTimeSlot();
                            $('#userId').val(userId);
                            form.val('example4', {
                                checkIn: 0,
                                checkOut: 0,
                                autoSchPlan: 1,
                                autoDays: '',
                                autoHours: '',
                                isCount: 1,
                                isOverTime: 1,
                                isHolidays: 1,
                                isExamine: 1
                            })
                            form.render();
                        }
                    });
                },
                reload: function () {
                    var depId = $('#depId');
                    var userId = formSelects.value('userName', 'valStr');

                    var startTime = $('#test1');
                    var endTime = $('#test2');
                    //执行重载
                    table.reload('testReload', {
                        where: {
                            depId: depId.val(),
                            userId:userId,
                            startTime: startTime.val(),
                            endTime: endTime.val()
                        }
                        // , page: {
                        //     curr: 1
                        // }
                    });
                }
            };

            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });


            $('.cancel-layer').on('click', function () {
                layer.close(layer.index);
                layer.close(layerIndex);
                layer.closeAll();
            })

            $('#personArrange').on('click',function(){
                active.personArrange();
            })

            //增加时间段
            var runAddTimeEvent = function (data) {
                $('#numRunId').val(data.numRunId);
                form.val('example', {
                    'classTimeSlot': '',
                    'dateTimeSlot': '',
                    'isAddWork': '',
                    'cycleUnit': '',
                    'addWorkTime': ''
                })
                layerIndex = layer.open({
                    type: 1
                    , title: '添加班次时段' //不显示标题栏
                    , area: '430px;'
                    , shade: 0.8
                    , id: 'LAY_layuipro5' //设定一个id，防止重复弹出
                    // ,btn: ['确定', '取消']
                    // ,btnAlign: 'c'
                    , moveType: 1 //拖拽模式，0或者1
                    , content: $('#addTimeMask')
                    , success: function (layero, index) {
                        // initDateTimeSlot(data);
                        formSelects.render('selectId');
                        // initGradeTime();

                        form.render();

                    }
                });
                return false;
            }
            //临时排班 添加时段
            var runAddTimeTemporary = function (data) {
                $('#temporaryNumRunId').val(data.numRunId);
                $('#userIdTemporary').val(data.userId);
                form.val('example', {
                    'classTimeSlot': '',
                    'startDays':'',
                    'isAddWork': 0,
                    'cycleUnit': '',
                    'addWorkTime':''
                })
                layerIndex = layer.open({
                    type: 1
                    , title: '添加班次时段' //不显示标题栏
                    , area: '430px;'
                    , shade: 0.8
                    , id: 'LAY_layuipro5' //设定一个id，防止重复弹出
                    // ,btn: ['确定', '取消']
                    // ,btnAlign: 'c'
                    , moveType: 1 //拖拽模式，0或者1
                    , content: $('#temporary')
                    , success: function (layero, index) {
                        // console.log(layero);
                        // initDateTimeSlot(data);
                        initTemplateDateTime();
                        formSelects.render('selectId');
                        initGradeTime();

                        form.render();

                    }
                });
                return false;
            }
        });
    }

    // 初始化临时排班中要添加时段的日期
    function initTemplateDateTime(){
        var startTime = $('#test1').val();
        var endTime = $('#test2').val();
        //日期相隔的每一天 即显示在y轴上的日期
        var yData = formatterDayByDay(startTime.split(' ')[0], endTime.split(' ')[0]);
        var obj = {};
        for(var i = 0; i < yData.length;i++){
            obj[i] = yData[i];
        }
        var html = '';
        for(var i in yData){
            html += '<option name="dateTimeSlot" value="' + i + '">' + yData[i] + '</option>'
        }
        $('#dateTimeSlot').html(html);
    }


    //初始化部门
    function initDept() {
        $.ajax({
            type: "POST",
            async: false,
            data: "",
            url: "${bathPath}/dept/selectDpetName.action",
            success: function (msg) {
                var html = "";
                html += "<option value=''>" + '请选择' + "</option>";
                for (var i = 0; i < msg.length; i++) {
                    html += "<option value='" + msg[i].depID + "'>" + msg[i].depName + "</option>";
                }
                $("#depId").html(html);
            }
        });
    }

    //初始化班次设置中的班次名称
    function initNumRunName() {
        $.ajax({
            type: "POST",
            async: false,
            data: "",
            url: "${bathPath}/numRun/selectNumRunName.action",
            success: function (msg) {
                var html = "";
                html += "<option value=''>" + '请选择' + "</option>";
                for (var i = 0; i < msg.length; i++) {
                    html += "<option value='" + msg[i].id + "'>" + msg[i].name  + "</option>";
                }

                // var html2 = '';
                // for (var i = 0; i < msg.length; i++) {
                //     html2 += '<input type="checkbox" name="canArrangeClass" lay-skin="primary" title="' + msg[i].name + '" value="' + msg[i].id + '" checked="">';
                // }
                $("#selectClass,#numRunId2,#temporaryClassTimeSlot").html(html);
                // $('#canArrangeClass').html(html2);
            }
        });
    }


    // 初始化人员排班弹出层中的选择班次列表
    function initArrangeList() {
        $.ajax({
            type: "POST",
            async: false,
            data: "",
            url: "${bathPath}/dept/selectDpetName.action",
            success: function (msg) {
                var html = "";
                html += "<option value=''>" + '请选择' + "</option>";
                for (var i = 0; i < msg.length; i++) {
                    html += "<option value='" + msg[i].depID + "'>" + msg[i].depName + "</option>";
                }
                $("#depId").html(html);
            }
        });
    }

    //获取时间范围内选中的日期
    function getSelectDate(startTime,endTime,dataJson,table){
        var yData = [];
        var resDataArr = [];
        var params = Object.assign({},dataJson);
        yData = formatterDayByDay(startTime.split(' ')[0], endTime.split(' ')[0]);
        var numRunId = params.numRunId;
        $.ajax({
            type: "POST",
            async: false,
            data: {numRunId:numRunId,deilType:1},
            contentType:"application/x-www-form-urlencoded",
            url: '${bathPath}/numRunDeil/findNumRunDeilByNumRunId.action',
            success: function (res) {
                var resData = res.data;
                if(resData.length === 0){
                    layer.alert('该班次暂无时段!',{
                        icon:2,
                        title:'提示'
                    })
                    return;
                }

                for(var i = 0; i < resData.length;i++){
                    resData[i].runStartTime = startTime + '.0';
                    resData[i].runEndTime = endTime + '.0';
                }
                var arr = getTotalEchartsDataForArrange(resData, yData, startTime, endTime,dataJson,'不含跨天');
                resDataArr = resDataArr.concat(arr);
                var timeArr = [];//时间数组
                for(var j = 0;j < resDataArr.length; j ++){
                    var time = resDataArr[j].startTime;
                    var standardTime = formatTime(time);
                    timeArr.push(standardTime);
                }
                timeArr = uniq(timeArr);
                params.startTime = startTime;
                params.endTime = endTime;
                params.startTimeStr = timeArr.toString();
                params.endTimeStr = timeArr.toString();
                $.ajax({
                    type: 'POST',
                    data: params,
                    contentType: "application/x-www-form-urlencoded",
                    url: '${bathPath}/userStatistics/insert.action',
                    success: function (data) {
                        if (data == 'SUCCESS') {

                            layer.closeAll();
                            table.reload('testReload', {
                                where: {}
                                // , page: {
                                //     curr: 1
                                // }
                            });
                        }
                    }
                })
            }
        })
    }

    function initEcharts(params) {
        $('#chartContent').width($('#chartContent').width());
        $('#chartContent').height($('#chartContent').height());
        if (!myChart) {
            myChart = echarts.init(document.getElementById('chartContent'));//加载图形的div
        }
        var colors = ['#2EC7C9'];//颜色
        var state = ['时间段'];//状态
        var yData = [];
        var startTime = $('#test1').val();
        var endTime = $('#test2').val();
        // var units = data.units;
        // var cycle = data.cycle;
        //日期相隔的每一天 即显示在y轴上的日期
        yData = formatterDayByDay(startTime.split(' ')[0], endTime.split(' ')[0]);
        // var newYData = [];
        //如果周期为周  格式化yData的数据为不带星期的日期  即'2019-05-06 一' 格式化为'2019-05-06'
        // if(units && units === 1){
        //     for(var d = 0;d < yData.length; d++){
        //         newYData.push(yData[d].split(' ')[0]);
        //     }
        // }else{
        //     newYData = yData.slice(0);
        // }
        // if(units && units === 1){
        //     startTime = startTime.split(' ')[0] + ' '+getMyDay(startTime);
        //     endTime = endTime.split(' ')[0] + ' '+getMyDay(endTime);
        // }

        var dataJson = [{
            itemStyle: {normal: {color: 'rgba(0,0,0,0)'}},//条形颜色
            name: '时间段',
            value: ['','1970/01/01 00:00', '1970/01/01 24:00']//0,1,2代表y轴的索引，后两位代表x轴数据开始和结束
        }];

        // deilType  1为班次管理中查看  2为人员安排中的查看
        var dataParams = {
            // numRunId: data.numRunId,
            // startTime: startTime,
            userId:params.userId
            // endTime: endTime
            // deilType:2
        }
        // 获取时间段数据
        $.ajax({
            type: "POST",
            async: false,
            data: dataParams,
            contentType: "application/x-www-form-urlencoded",
            url: '${bathPath}/numRunDeil/selectAll.action',
            success: function (res) {
                var resData = res.data;
                var option = null;
                if (resData.length > 0) {
                    // echart配置
                   var arrData = [];
                   var resDataArr = [];
                   for(var i = 0; i < resData.length;i++){
                       var arr = getTotalEchartsData(dataParams.userId,resData[i],yData,startTime,endTime);
                       resDataArr = resDataArr.concat(arr);
                   }
                    for (var i = 0; i < resDataArr.length; i++) {
                        arrData.push({
                            itemStyle: {normal: {color: colors[0]}},
                            name: '时间段',
                            value: [resDataArr[i].sDays, formatterTimeStr(resDataArr[i].schStartTime), formatterTimeStr(resDataArr[i].schEndTime)]
                        })
                    }
                    dataJson = dataJson.concat(arrData);
                    option = {
                        color: colors,
                        tooltip: {//提示框
                            formatter: function (params) {
                                return params.name + ':' + params.value[1].split(' ')[1] + '~' + params.value[2].split(' ')[1];
                            }//数据的值
                        },
                        legend: {//图例
                            data: state,
                            bottom: '1%',
                            selectedMode: false, // 图例设为不可点击
                            textStyle: {
                                color: '#000'
                            },
                            // show: false
                        },
                        grid: {//绘图网格
                            left: '3%',
                            right: '3%',
                            top: '1%',
                            bottom: '10%',
                            containLabel: true
                        },
                        xAxis: {
                            type: 'time', interval: 3600*1000, axisLabel: {
                                formatter: function (value) {
                                    // var val = '2009/6/1 '+value;
                                    var date = new Date(value);
                                    var time = getzf(date.getHours());
                                    return time;

                                    function getzf(num) {
                                        if (parseInt(num) < 10) {
                                            num = '0' + num;
                                        }
                                        return num;
                                    }
                                },
                            },
                            position: 'top'
                        },
                        // dataZoom: [{
                        //     type: 'slider',
                        //     show: true,
                        //     yAxisIndex: [0],
                        //     left: '0',
                        //     bottom: '10%',
                        //     start: 0,
                        //     end: 50 //初始化滚动条
                        // }],
                        yAxis: {
                            data: yData,
                            axisLabel:{
                                formatter: function (value, index) {//value当前值，index当前索引
                                    return value;
                                }
                            }
                        },
                        series: [
                            // 用空bar来显示四个图例
                            {name: state[0], type: 'bar', data: []},
                            // {name: state[1], type: 'bar', data: []},
                            {
                                type: 'custom', renderItem: function (params, api) {//开发者自定义的图形元素渲染逻辑，是通过书写 renderItem 函数实现的
                                    var categoryIndex = api.value(0);//这里使用 api.value(0) 取出当前 dataItem 中第一个维度的数值。
                                    var start = api.coord([api.value(1), categoryIndex]); // 这里使用 api.coord(...) 将数值在当前坐标系中转换成为屏幕上的点的像素值。
                                    var end = api.coord([api.value(2), categoryIndex]);
                                    var height = 24;//柱体宽度
                                    return {
                                        type: 'rect',// 表示这个图形元素是矩形。还可以是 'circle', 'sector', 'polygon' 等等。
                                        shape: echarts.graphic.clipRectByRect({ // 矩形的位置和大小。
                                            x: start[0],
                                            y: start[1] - height / 2,
                                            width: end[0] - start[0],
                                            height: height
                                        }, { // 当前坐标系的包围盒。
                                            x: params.coordSys.x,
                                            y: params.coordSys.y,
                                            width: params.coordSys.width,
                                            height: params.coordSys.height
                                        }),
                                        style: api.style()
                                    };
                                },
                                encode: {
                                    x: [1, 2], // data 中『维度1』和『维度2』对应到 X 轴
                                    y: 0// data 中『维度0』对应到 Y 轴
                                },
                                data: dataJson
                            }
                        ]
                    };
                } else {
                    option = {
                        color: colors,
                        tooltip: {//提示框
                            formatter: function (params) {
                                return params.name + ':' + params.value[1].split(' ')[1] + '~' + params.value[2].split(' ')[1];
                            }//数据的值
                        },
                        legend: {//图例
                            data: state,
                            bottom: '1%',
                            selectedMode: false, // 图例设为不可点击
                            textStyle: {
                                color: '#000'
                            },
                            // show: false
                        },
                        grid: {//绘图网格
                            left: '3%',
                            right: '3%',
                            top: '1%',
                            bottom: '10%',
                            containLabel: true
                        },
                        xAxis: {
                            type: 'time',
                            interval: 3600 * 1000,
                            axisLabel: {
                                formatter: function (value) {
                                    // var val = '2009/6/1 '+value;
                                    var date = new Date(value);
                                    var time = getzf(date.getHours());
                                    return time;
                                },
                            },
                            position: 'top'
                            // data: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
                        },
                        // dataZoom: [{
                        //     type: 'slider',
                        //     show: true,
                        //     yAxisIndex: [0],
                        //     left: '0',
                        //     bottom: '10%',
                        //     start: 0,
                        //     end: 50 //初始化滚动条
                        // }],
                        yAxis: {
                            data: yData
                        },
                        series: [
                            // 用空bar来显示四个图例
                            {name: state[0], type: 'bar', data: []},
                            // {name: state[1], type: 'bar', data: []},
                            {
                                type: 'custom', renderItem: function (params, api) {//开发者自定义的图形元素渲染逻辑，是通过书写 renderItem 函数实现的
                                    var categoryIndex = api.value(0);//这里使用 api.value(0) 取出当前 dataItem 中第一个维度的数值。
                                    var start = api.coord([api.value(1), categoryIndex]); // 这里使用 api.coord(...) 将数值在当前坐标系中转换成为屏幕上的点的像素值。
                                    var end = api.coord([api.value(2), categoryIndex]);
                                    var height = 24;//柱体宽度
                                    return {
                                        type: 'rect',// 表示这个图形元素是矩形。还可以是 'circle', 'sector', 'polygon' 等等。
                                        shape: echarts.graphic.clipRectByRect({ // 矩形的位置和大小。
                                            x: start[0],
                                            y: start[1] - height / 2,
                                            width: end[0] - start[0],
                                            height: height
                                        }, { // 当前坐标系的包围盒。
                                            x: params.coordSys.x,
                                            y: params.coordSys.y,
                                            width: params.coordSys.width,
                                            height: params.coordSys.height
                                        }),
                                        style: api.style()
                                    };
                                },
                                encode: {
                                    x: [1, 2], // data 中『维度1』和『维度2』对应到 X 轴
                                    y: 0// data 中『维度0』对应到 Y 轴
                                },
                                data: dataJson
                            }
                        ]
                    };
                }

                if(yData.length > 15){
                    var dataZoom = [];
                    var objData = {
                        type: 'slider',
                        show: true,
                        yAxisIndex: [0],
                        left: '0',
                        bottom: '10%',
                        start: 0,
                        end: 50 //初始化滚动条
                    };
                    dataZoom.push(objData);
                    option.dataZoom = dataZoom
                }
                myChart.clear();
                myChart.setOption(option);//引用
            }
        })
    }

    function getTotalEchartsData(userId,resData,yData,startTime,endTime){

        // var sDaysArr = [];
        var sDaysList = [];
        for(var i = 0; i < resData.length;i++){
            sDaysList.push(getDay(resData[i].sDays%7));
        }
        var units = resData[0].units;
        var cycle = resData[0].cycle;
        var runEndTime = resData[0].runEndTime;
        var runStartTime = resData[0].runStartTime;
        var timeRunStart = new Date(runStartTime.split(' ')[0]+' 00:00:00').getTime();
        var timeRunEnd = new Date(runEndTime.split(' ')[0]+' 00:00:00').getTime();


        var time1 = new Date(startTime).getTime();
        var time2 = new Date(runStartTime.split(' ')[0] + ' 00:00:00').getTime();
        var time3 = new Date(endTime).getTime();
        var time4 = new Date(runEndTime.split(' ')[0] + ' 00:00:00').getTime();
        var diffStart =  time1 - time2;//开始时间与当前班次的开始时间差
        var timeStartToEnd = time1 - time4;//开始时间与当前班次结束时间差
        var timeEndToEnd = time3 - time4;//结束时间与当前班次结束时间差
        var timeEndToStart = time3 - time2;//结束时间与当前班次开始时间差

        var startDDay = resData[0].schStartTime;
        var endDDay = resData[0].schEndTime;
        var startTimeStrDay = parseInt(startDDay.split(' ')[1].split(':')[0], 10);
        var endTimeStrDay = parseInt(endDDay.split(' ')[1].split(':')[0], 10);
        if(new Date(runEndTime.split(' ')[0]+' 00:00:00').getTime() >= new Date(endTime).getTime()){
            var endTimeStamp = endTime.split(' ')[0] + ' '+getMyDay(endTime.split(' ')[0]);
        }else{
            var endTimeStamp = runEndTime.split(' ')[0] + ' '+getMyDay(runEndTime.split(' ')[0]);
        }



        var diffEnd = yData.indexOf(endTimeStamp);


        //为天时  从第一天开始循环
        if(units === 2){
            for (var i = 0; i < resData.length; i++) {

                var startTimeString = formatTime(resData[i].startTime).split(' ')[0];
                startTimeString = startTimeString + ' '+getMyDay(startTimeString);
                //格式化临时排班的sDays
                if(yData.indexOf(startTimeString) >= 0 && resData[i].deilType !== 1){
                    // sDaysArr.push(yData.indexOf(startTime));
                    resData[i].sDays = yData.indexOf(startTimeString);
                }else if(yData.indexOf(startTimeString) < 0 && resData[i].deilType === 2){
                    resData[i].sDays = '';
                }else{
                    if((diffStart <= 0 && timeEndToStart < 0) || (timeStartToEnd > 0 && timeEndToEnd > 0)){
                        // 起止时间都小于当前班次的开始时间 或者 起止时间都大于当前班次结束时间
                        //且为非跨天状态
                        // if(startTimeStrDay < endTimeStrDay){
                            resData[i].sDays = '';
                        // }
                    }else if(diffStart <= 0  && timeEndToStart >= 0){
                        if(i <= diffEnd){
                            var day = parseInt(Math.abs(diffStart)/1000/60/60/24,10);
                            var diffDay = day;
                            resData[i].sDays = resData[i].sDays + diffDay;
                        }else{
                            resData[i].sDays = '';
                        }
                    }
                }


                // 将startTime重构
                if(resData[i].sDays !== '' && yData[resData[i].sDays]){
                    resData[i].startTime = new Date(yData[resData[i].sDays].split(' ')[0] + ' 00:00:00').getTime();
                    resData[i].endTime = new Date(yData[resData[i].sDays].split(' ')[0] + ' 00:00:00').getTime();
                }


            }

            var copyYData = [];
            for(var k = 0; k < yData.length;k++){
                copyYData.push(new Date(yData[k].split(' ')[0]+ ' 00:00:00').getTime());
            }
            for (var j = 0; j < resData.length; j++) {
                resData[j].startTime = resData[j].sDays >= 0 ? copyYData[resData[j].sDays] : '';
            }
        }else{
            for (var i = 0; i < resData.length; i++) {

                var startTimeString = formatTime(resData[i].startTime).split(' ')[0];
                startTimeString = startTimeString + ' '+getMyDay(startTimeString);
                //格式化临时排班的sDays
                if(yData.indexOf(startTimeString) >= 0 && resData[i].deilType !== 1){
                    // sDaysArr.push(yData.indexOf(startTime));
                    resData[i].sDays = yData.indexOf(startTimeString);
                }else if(yData.indexOf(startTimeString) < 0 && resData[i].deilType === 2){
                    resData[i].sDays = '';
                }else{
                    if((diffStart <= 0 && timeEndToStart <= 0) || (timeStartToEnd > 0 && timeEndToEnd > 0)){
                        // 起止时间都小于当前班次的开始时间 或者 起止时间都大于当前班次结束时间
                        resData[i].sDays = '';
                    }else if(diffStart < 0 && timeEndToStart > 0){
                        // 开始时间小于当前班次开始时间  结束时间大于当前班次开始时间
                        //     if(i <= diffEnd){
                        //         var diffDay = parseInt(Math.abs(diffStart)/1000/60/60/24,10) - 1;
                        //         // 为月时天数需减一
                        //         if(units === 3){
                        //             diffDay = diffDay - 1 < 0 ? 0 : diffDay - 1;
                        //         }
                        //         resData[i].sDays = resData[i].sDays + diffDay;
                        //         // resData[i].startTime = new Date(getDateStr(resData[i].startTime,resData[i].sDays) + ' 00:00:00').getTime()
                        //     }else{
                        //         resData[i].sDays = '';
                        //     }
                    }else if(diffStart === 0  && timeEndToStart >= 0){
                        if(i <= diffEnd){
                            var diffDay = parseInt(Math.abs(diffStart)/1000/60/60/24,10);
                            // 为月时天数需减一
                            if(units === 3){
                                diffDay = diffDay - 1 < 0 ? 0 : diffDay - 1;
                            }
                            resData[i].sDays = resData[i].sDays + diffDay;
                            // resData[i].startTime = new Date(getDateStr(resData[i].startTime,resData[i].sDays) + ' 00:00:00').getTime()
                        }else{
                            resData[i].sDays = '';
                        }
                    }
                }


                // 将startTime重构
                if(resData[i].sDays !== '' && yData[resData[i].sDays]){
                    resData[i].startTime = new Date(yData[resData[i].sDays].split(' ')[0] + ' 00:00:00').getTime();
                    resData[i].endTime = new Date(yData[resData[i].sDays].split(' ')[0] + ' 00:00:00').getTime();
                }


            }
            for (var i = 0; i < resData.length; i++) {
                //为周排班时
                if(units === 1){
                    // 判断sDays 与yData的星期是否相等
                    // sDays 0:星期一 1:星期二  以此类推
                    for(var h = 0; h < yData.length; h++){
                        var item = yData[h].split(' ');
                        var week = item[1];
                        var dateYData = item[0];
                        var timeY = new Date(dateYData + ' 00:00:00').getTime();
                        if( timeY >= timeRunStart && timeY <= timeRunEnd){
                            if(week === getDay(resData[i].sDays%7) && sDaysList.indexOf(week) > -1){
                                resData[i].startTime = timeY;
                                resData[i].sDays = h;
                                resData[i].endTime = timeY;
                                break;
                            }
                        }
                    }
                }
            }
        }


        // 判断所选时间段范围内包含几个单位为周的周期
        var startTimeStampStr = new Date(runStartTime.split(' ')[0]+' 00:00:00').getTime();
        var endTimeStampStr = new Date(runEndTime.split(' ')[0]+' 00:00:00').getTime();
        var dayCount = (endTimeStampStr - startTimeStampStr)/1000/60/60/24 + 1;//得到天数
        var newData = resData.slice(0);
        var cycleNum = dayCount/cycle;
        if(units === 1){
            var unitsDays = 7;
        }else if(units === 2){
            var unitsDays = cycle;
        }else if(units === 3){
            var unitsDays = 30;
        }
       if(parseInt(units,10) === 1 || parseInt(units,10) === 2 || parseInt(units,10) === 3) {
            //判断天数差是否大于一个循环且周期单位为月或天或周

            for (var t = 1; t < cycleNum; t++) {
                for (var k in newData) {
                    if (newData[k].deilType === 1) {
                        var days = parseInt(newData[k].sDays, 10) + t * unitsDays;
                        resData.push({
                            deilType: newData[k].deilType,
                            schStartTime: newData[k].schStartTime,
                            schEndTime: newData[k].schEndTime,
                            sDays: days <= diffEnd ?  days: '',
                            startTime: days <= diffEnd ? new Date(yData[days].split(' ')[0] + ' 00:00:00').getTime():''
                        })
                    }

                    if(diffStart < 0  && timeEndToEnd <= 0){
                        // 开始时间小于当前班次开始时间 且结束时间小于当前班次结束时间
                        if(!(resData[k].startTime >= time2 && (resData[k].startTime <= time3 || (resData[k].crossDay && resData[k].startTime <= time3 + 24*60*60*1000)))){
                            resData[k].sDays = '';
                        }
                    }
                }
            }
            // console.log(resData);
            // debugger;
        }
        // var isTwoTime = false;//是否跨天
        // 人员排班时  不需要跨天
        if(arguments.length === 5){
            // 判断是否跨天
            for(var j in resData) {
                var start = resData[j].schStartTime;
                var end = resData[j].schEndTime;
                var startTimeStr = parseInt(start.split(' ')[1].split(':')[0], 10);
                var endTimeStr = parseInt(end.split(' ')[1].split(':')[0], 10);
                var fStartTime = formatTime(resData[j].startTime).split(' ')[0] +' '+start.split(' ')[1] + '-'+ end.split(' ')[1];
                if (startTimeStr > endTimeStr) {
                    resData[j].needDelete = true;
                    // isTwoTime = true;
                    resData.push({
                        crossTime:fStartTime,
                        crossDay:'start',
                        deilType: resData[j].deilType,
                        schStartTime: start,
                        schEndTime: start.split(' ')[0] + ' 24:00:00.0',
                        sDays: resData[j].sDays,
                        startTime: resData[j].sDays >= 0 && yData[resData[j].sDays] ? new Date(yData[resData[j].sDays].split(' ')[0] + ' 00:00:00').getTime() : ''
                    })

                    var date2 = getDate(endTime.split(' ')[0]);
                    date2.setDate(date2.getDate() + 1);
                    var date2Day = date2.getFullYear() + "-" + getzf(date2.getMonth() + 1) + "-" + getzf(date2.getDate());
                    // 如果跨天超过查看时间的起止时间的结束日期  增加一天
                    if(yData[resData[j].sDays] === yData[yData.length - 1]){
                        yData[yData.length] = date2Day + ' '+getMyDay(date2Day);
                    }
                    resData.push({
                        crossTime:fStartTime,
                        crossDay:'end',
                        deilType: resData[j].deilType,
                        schStartTime: start.split(' ')[0] + ' 00:00:00.0',
                        schEndTime: end,
                        sDays: parseInt(resData[j].sDays, 10) + 1,
                        startTime: resData[j].sDays >= 0 && yData[resData[j].sDays] ? new Date(yData[parseInt(resData[j].sDays, 10) + 1].split(' ')[0] + ' 00:00:00').getTime() : ''
                    })
                }
            }
        }




        // //如果存在跨天的时间段
        // if(isTwoTime){
        //     //为避免跨时间情况,统一多增一天时间
        //     var date2 = getDate(endTime.split(' ')[0]);
        //     date2.setDate(date2.getDate() + 1);
        //     var date2Day = date2.getFullYear() + "-" + getzf(date2.getMonth() + 1) + "-" + getzf(date2.getDate());
        //     yData[yData.length] = date2Day + ' '+getMyDay(date2Day);
        // }
        for(var i = 0; i < resData.length; i++){
            if(resData[i].sDays === '' || resData[i].startTime === '' || isNaN(parseInt(resData[i].sDays)) || isNaN(parseInt(resData[i].startTime)) || resData[i].needDelete){
                resData.splice(i,1);
                i--;
            }
        }


        for(var k = 0; k < resData.length; k++){
            if(diffStart < 0  && timeEndToEnd <= 0){
                // 开始时间小于当前班次开始时间 且结束时间小于当前班次结束时间
                if(!(resData[k].startTime >= time2 && (resData[k].startTime <= time3 || (resData[k].crossDay && resData[k].startTime <= time3 + 24*60*60*1000)))){
                    resData[k].sDays = '';
                }
            }else if(diffStart > 0 && timeStartToEnd <= 0 && timeEndToEnd >= 0){
                // 开始时间大于当前班次开始时间且小于当前班次结束时间 且结束时间大于当前班次结束时间
                // resData[i].sDays = resData[i].sDays;
                if(resData[k].startTime < time1 || resData[k].startTime > time4){
                    resData[k].sDays = '';
                }
            }
        }
        var newResData = '';
        //isHolidays为1时  有效即过滤节假日  为0时  忽略即不需过滤节假日
        $.ajax({
            type: 'POST',
            async:false,
            data: {userId:userId},
            contentType: "application/x-www-form-urlencoded",
            url: '${bathPath}/userStatistics/findUserStatisticsById.action',
            success:function(result){
                var isHolidays = result[0].isHolidays;
                if(parseInt(isHolidays,10) === 0){
                    newResData = resData;
                }else if(parseInt(isHolidays,10) === 1){
                    //过滤节假日
                    newResData = filterHolidays(resData);
                }
            }
        })
        for(var i = 0; i < newResData.length; i++){
            if(newResData[i].sDays === '' || newResData[i].startTime === '' || isNaN(parseInt(newResData[i].sDays)) || isNaN(parseInt(newResData[i].startTime)) ||newResData[i].needDelete){
                newResData.splice(i,1);
                i--;
            }
        }
        resData = unCommon(newResData);
        resData.sort(compare('sDays'));


        return resData;
    }


    // 人员排班时调用的方法
    function getTotalEchartsDataForArrange(resData,yData,startTime,endTime,dataJson){
        // var sDaysArr = [];
        var sDaysList = [];
        for(var i = 0; i < resData.length;i++){
            sDaysList.push(getDay(resData[i].sDays%7));
        }
        var units = resData[0].units;
        var cycle = resData[0].cycle;
        var runEndTime = resData[0].runEndTime;
        var runStartTime = resData[0].runStartTime;
        var timeRunStart = new Date(runStartTime.split(' ')[0]+' 00:00:00').getTime();
        var timeRunEnd = new Date(runEndTime.split(' ')[0]+' 00:00:00').getTime();


        var time1 = new Date(startTime).getTime();
        var time2 = new Date(runStartTime.split(' ')[0] + ' 00:00:00').getTime();
        var time3 = new Date(endTime).getTime();
        var time4 = new Date(runEndTime.split(' ')[0] + ' 00:00:00').getTime();
        var diffStart =  time1 - time2;//开始时间与当前班次的开始时间差
        var timeStartToEnd = time1 - time4;//开始时间与当前班次结束时间差
        var timeEndToEnd = time3 - time4;//结束时间与当前班次结束时间差
        var timeEndToStart = time3 - time2;//结束时间与当前班次开始时间差

        if(new Date(runEndTime.split(' ')[0]+' 00:00:00').getTime() >= new Date(endTime).getTime()){
            var endTimeStamp = endTime.split(' ')[0] + ' '+getMyDay(endTime.split(' ')[0]);
        }else{
            var endTimeStamp = runEndTime.split(' ')[0] + ' '+getMyDay(runEndTime.split(' ')[0]);
        }
        var diffEnd = yData.indexOf(endTimeStamp);
        for (var i = 0; i < resData.length; i++) {

            var startTimeString = formatTime(resData[i].startTime).split(' ')[0];
            startTimeString = startTimeString + ' '+getMyDay(startTimeString);
            //格式化临时排班的sDays
            if(yData.indexOf(startTimeString) >= 0 && resData[i].deilType !== 1){
                // sDaysArr.push(yData.indexOf(startTime));
                resData[i].sDays = yData.indexOf(startTimeString);
            }else if(yData.indexOf(startTimeString) < 0 && resData[i].deilType === 2){
                resData[i].sDays = '';
            }else{
                if((diffStart <= 0 && timeEndToStart <= 0) || (timeStartToEnd > 0 && timeEndToEnd > 0)){
                    // 起止时间都小于当前班次的开始时间 或者 起止时间都大于当前班次结束时间
                        resData[i].sDays = '';
                }else if(diffStart < 0 && timeEndToStart > 0){
                    // 开始时间小于当前班次开始时间  结束时间大于当前班次开始时间
                    //     if(i <= diffEnd){
                    //         var diffDay = parseInt(Math.abs(diffStart)/1000/60/60/24,10) - 1;
                    //         // 为月时天数需减一
                    //         if(units === 3){
                    //             diffDay = diffDay - 1 < 0 ? 0 : diffDay - 1;
                    //         }
                    //         resData[i].sDays = resData[i].sDays + diffDay;
                    //         // resData[i].startTime = new Date(getDateStr(resData[i].startTime,resData[i].sDays) + ' 00:00:00').getTime()
                    //     }else{
                    //         resData[i].sDays = '';
                    //     }
                }else if(diffStart === 0  && timeEndToStart >= 0){
                    if(i <= diffEnd){
                        var diffDay = parseInt(Math.abs(diffStart)/1000/60/60/24,10);
                        // 为月时天数需减一
                        if(units === 3){
                            diffDay = diffDay - 1 < 0 ? 0 : diffDay - 1;
                        }
                        resData[i].sDays = resData[i].sDays + diffDay;
                        // resData[i].startTime = new Date(getDateStr(resData[i].startTime,resData[i].sDays) + ' 00:00:00').getTime()
                    }else{
                        resData[i].sDays = '';
                    }
                }
            }


            // 将startTime重构
            if(resData[i].sDays !== '' && yData[resData[i].sDays]){
                resData[i].startTime = new Date(yData[resData[i].sDays].split(' ')[0] + ' 00:00:00').getTime();
                resData[i].endTime = new Date(yData[resData[i].sDays].split(' ')[0] + ' 00:00:00').getTime();
            }


        }
        for (var i = 0; i < resData.length; i++) {
            //为周排班时
            if(units === 1){
                // 判断sDays 与yData的星期是否相等
                // sDays 0:星期一 1:星期二  以此类推
                for(var h = 0; h < yData.length; h++){
                    var item = yData[h].split(' ');
                    var week = item[1];
                    var dateYData = item[0];
                    var timeY = new Date(dateYData + ' 00:00:00').getTime();
                    if( timeY >= timeRunStart && timeY <= timeRunEnd){
                        if(week === getDay(resData[i].sDays%7) && sDaysList.indexOf(week) > -1){
                            resData[i].startTime = timeY;
                            resData[i].sDays = h;
                            resData[i].endTime = timeY;
                            break;
                        }
                    }
                }
            }
        }
        // 判断所选时间段范围内包含几个单位为周的周期
        var startTimeStampStr = new Date(runStartTime.split(' ')[0]+' 00:00:00').getTime();
        var endTimeStampStr = new Date(runEndTime.split(' ')[0]+' 00:00:00').getTime();
        var dayCount = (endTimeStampStr - startTimeStampStr)/1000/60/60/24 + 1;//得到天数
        var newData = resData.slice(0);
        var cycleNum = dayCount/cycle;
        if(units === 1){
            var unitsDays = 7;
        }else if(units === 2){
            var unitsDays = cycle;
        }else if(units === 3){
            var unitsDays = 30;
        }
        if(parseInt(units,10) === 1 || parseInt(units,10) === 2 || parseInt(units,10) === 3) {
            //判断天数差是否大于一个循环且周期单位为月或天或周

            for (var t = 1; t < cycleNum; t++) {
                for (var k in newData) {
                    if (newData[k].deilType === 1) {
                        var days = parseInt(newData[k].sDays, 10) + t * unitsDays;
                        resData.push({
                            deilType: newData[k].deilType,
                            schStartTime: newData[k].schStartTime,
                            schEndTime: newData[k].schEndTime,
                            sDays: days <= diffEnd ?  days: '',
                            startTime: days <= diffEnd ? new Date(yData[days].split(' ')[0] + ' 00:00:00').getTime():''
                        })
                    }

                    if(diffStart < 0  && timeEndToEnd <= 0){
                        // 开始时间小于当前班次开始时间 且结束时间小于当前班次结束时间
                        if(!(resData[k].startTime >= time2 && resData[k].startTime <= time3)){
                            resData[k].sDays = '';
                        }
                    }
                }
            }
        }


        // 人员排班时  不需要跨天
        if(arguments.length === 5){
            // 判断是否跨天
            for(var j in resData) {
                var start = resData[j].schStartTime;
                var end = resData[j].schEndTime;
                var startTimeStr = parseInt(start.split(' ')[1].split(':')[0], 10);
                var endTimeStr = parseInt(end.split(' ')[1].split(':')[0], 10);
                if (startTimeStr > endTimeStr) {
                    // isTwoTime = true;
                    resData.push({
                        deilType: resData[j].deilType,
                        schStartTime: start,
                        schEndTime: start.split(' ')[0] + ' 24:00:00.0',
                        sDays: resData[j].sDays,
                        startTime: resData[j].sDays && yData[resData[j].sDays] ? new Date(yData[resData[j].sDays].split(' ')[0] + ' 00:00:00').getTime() : ''
                    })

                    var date2 = getDate(endTime.split(' ')[0]);
                    date2.setDate(date2.getDate() + 1);
                    var date2Day = date2.getFullYear() + "-" + getzf(date2.getMonth() + 1) + "-" + getzf(date2.getDate());
                    // 如果跨天超过查看时间的起止时间的结束日期  增加一天
                    if(yData[resData[j].sDays] === yData[yData.length - 1]){
                        yData[yData.length] = date2Day + ' '+getMyDay(date2Day);
                    }
                    resData.push({
                        deilType: resData[j].deilType,
                        schStartTime: start.split(' ')[0] + ' 00:00:00.0',
                        schEndTime: end,
                        sDays: parseInt(resData[j].sDays, 10) + 1,
                        startTime: resData[j].sDays && yData[resData[j].sDays] ? new Date(yData[parseInt(resData[j].sDays, 10) + 1].split(' ')[0] + ' 00:00:00').getTime() : ''
                    })
                }
            }
        }

        for(var i = 0; i < resData.length; i++){
            if(resData[i].sDays === '' || resData[i].startTime === '' || isNaN(parseInt(resData[i].sDays)) || isNaN(parseInt(resData[i].startTime)) || resData[i].needDelete){
                resData.splice(i,1);
                i--;
            }
        }


        for(var k = 0; k < resData.length; k++){
            if(diffStart < 0  && timeEndToEnd <= 0){
                // 开始时间小于当前班次开始时间 且结束时间小于当前班次结束时间
                if(!(resData[k].startTime >= time2 && resData[k].startTime <= time3)){
                    resData[k].sDays = '';
                }
            }else if(diffStart > 0 && timeStartToEnd <= 0 && timeEndToEnd >= 0){
                // 开始时间大于当前班次开始时间且小于当前班次结束时间 且结束时间大于当前班次结束时间
                // resData[i].sDays = resData[i].sDays;
                if(resData[k].startTime < time1 || resData[k].startTime > time4){
                    resData[k].sDays = '';
                }
            }
        }
        //isHolidays为1时  过滤节假日  为0时  不过滤节假日   人员排班时未按isHoliday过滤
        //过滤节假日
        var isHolidays = parseInt(dataJson.isHolidays,10);
        if(isHolidays === 0){
            var newResData = resData;
        }else{
            var newResData = filterHolidays(resData);
        }

        for(var i = 0; i < newResData.length; i++){
            if(newResData[i].sDays === '' || newResData[i].startTime === '' || isNaN(parseInt(newResData[i].sDays)) || isNaN(parseInt(newResData[i].startTime)) || newResData[i].needDelete){
                newResData.splice(i,1);
                i--;
            }
        }
        resData = unCommon(newResData);
        resData.sort(compare('sDays'));


        return resData;
    }


    //过滤节假日 周期为月或天时
    function filterHolidays(resData){
        var newData = resData.slice(0);
        $.ajax({
            type: 'POST',
            async:false,
            contentType: "application/x-www-form-urlencoded",
            url: '${bathPath}/holidays/selectAll.action',
            success: function (data) {
                var dates = getHolidays(data);
                var newDates = [];
                for(var k = 0; k < dates.length;k++){
                    newDates.push(dates[k].split(' ')[0]);
                }
                for (var m = 0; m < resData.length; m++) {
                    var newStartTimes = formatTime(resData[m].startTime).split(' ')[0];
                    // 判断是否为跨天
                    if(resData[m].crossDay){
                        for (var h = m+1; h < resData.length; h++) {
                            var newStartCopyTimes = formatTime(resData[h].startTime).split(' ')[0];
                            //判断是否为同一日期拆分的跨天日期
                            if(resData[m].crossTime === resData[h].crossTime){
                                if(resData[m].crossDay === 'start' && resData[h].crossDay === 'end'  && resData[m].deilType === 1 && resData[h].deilType === 1){
                                    // 跨天日期为前半部分不在节假日日期列表中而后半部分在节假日列表中
                                    if(newDates.indexOf(newStartTimes) === -1 && newDates.indexOf(newStartCopyTimes) > -1){
                                        newData[h].sDays =  newData[h].sDays;
                                        break;
                                    }else if((newDates.indexOf(newStartTimes) > -1 && newDates.indexOf(newStartCopyTimes) > -1) || (newDates.indexOf(newStartTimes) > -1 && newDates.indexOf(newStartCopyTimes) === -1)){
                                        // 跨天日期为前半部分和后半部分都在节假日列表中或者前半部分在节假日日期列表中而后半部分不在节假日列表中
                                        newData[m].sDays =  '';
                                        newData[h].sDays =  '';
                                        break;
                                    }
                                }else{
                                    // 如果不为跨天  判断开始日期是否在节假日日期列表中即可
                                    for (var n = 0; n < dates.length; n++) {
                                        if(newStartTimes === dates[n].split(' ')[0] && resData[m].deilType === 1){
                                            newData[m].sDays = '';
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }else{
                        // 如果不为跨天  判断开始日期是否在节假日日期列表中即可
                        for (var n = 0; n < dates.length; n++) {
                            if(newStartTimes === dates[n].split(' ')[0] && resData[m].deilType === 1){
                                newData[m].sDays = '';
                                break;
                            }
                        }
                    }

                }
            }
        })
        // newData.length = yData.length;
        return newData;
    }



    // 获取所有放假的节假日日期
    function getHolidays(data){
        var res = data.data;
        var arr = [];
        if(res.length > 0){
            for(var i in res){
                var holidays = res[i].holiDays;//放假天数
                var holidayTime = res[i].holidayTime;//放假日期
                var startTime = formatTime(holidayTime).split(' ')[0];
                var afterTime = getDateStr(holidayTime,holidays);
                arr = arr.concat(formatterDayByDay(startTime, afterTime,'holidays'));
            }
        }
        return arr;
    }

    //距离指定日期n天后的日期
    function getDateStr(time,AddDayCount){
        var dd = new Date(time);
        dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
        var y = dd.getFullYear();
        var m = getzf(dd.getMonth() + 1);
        var d = getzf(dd.getDate());
        return y+"-"+m+"-"+d;
    }

    function formatterTimeStr(str) {
        str = str.replace(/-/ig, '/');
        var index = str.lastIndexOf(':');
        var newStr = str.slice(0, index);
        return newStr;
    }




    function initGradeTime() {
        var html = ' <option value=""></option>';
        $.ajax({
            type: "POST",
            async: false,
            data: "",
            url: '${bathPath}/schClass/findSchClassName.action',
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    var str = formatTime(data[i].startTime).split(" ")[1];
                    var index = str.lastIndexOf(':');
                    var newStr = str.slice(0, index);
                    html += '<option value="' + data[i].id + '">' + data[i].schName + '('+ newStr +')</option>';
                }
                $('#classTimeSlot,#temporaryClassTimeSlot').html(html);

            }
        })
    }


    //计算开始时间和结束时间相隔天数  周期单位为周时需携带星期几
    function formatterDayByDay(startTime, endTime) {
        var date1 = getDate(startTime);
        var date2 = getDate(endTime);
        if (date1 > date2) {
            var tempDate = date1;
            date1 = date2;
            date2 = tempDate;
        }
        date1.setDate(date1.getDate() + 1);
        var id = 1;
        var units = arguments[2];
        //为周排班时  日期携带星期
        var week = getMyDay(startTime);
        var dates = [startTime + ' '+week];
        while (!(date1.getFullYear() == date2.getFullYear() && date1.getMonth() == date2.getMonth() && date1.getDate() == date2.getDate())) {
            var yearMonthDay = date1.getFullYear() + "-" + getzf(date1.getMonth() + 1) + "-" + getzf(date1.getDate());
            var weekDay = getMyDay(yearMonthDay);
            dates[id] = yearMonthDay + ' '+weekDay;
            id++;
            date1.setDate(date1.getDate() + 1);
        }

        if(arguments.length === 2){
            // 格式化临时排班中的时间
            dates[dates.length] = endTime + ' '+getMyDay(endTime);

            formatterTemploryYData(dates);
        }
        return dates;
    }

    var getDate = function (str) {
        var tempDate = new Date();
        var list = str.split("-");
        tempDate.setFullYear(list[0]);
        tempDate.setMonth(list[1] - 1);
        tempDate.setDate(list[2]);
        return tempDate;
    }

    // 格式化临时排班中的添加时段
    function formatterTemploryYData(dateArr) {
        var obj = {};
        for (var i = 0; i < dateArr.length; i++) {
            obj[i] = dateArr[i];
        }
        localStorage.setItem('unitsDate', JSON.stringify(obj));
    }

    function getzf(num) {
        if (parseInt(num) < 10) {
            num = '0' + num;
        }
        return num;
    }
    //获取指定日期为星期几
    function getMyDay(dateStr){
        var week;
        var date = new Date(dateStr);
        if(date.getDay()==0) week="日"
        if(date.getDay()==1) week="一"
        if(date.getDay()==2) week="二"
        if(date.getDay()==3) week="三"
        if(date.getDay()==4) week="四"
        if(date.getDay()==5) week="五"
        if(date.getDay()==6) week="六"
        return week;
    }

    function getDay(day){
        var week;
        switch(day){
            case 0:
                week = '一';
                break;
            case 1:
                week = '二';
                break;
            case 2:
                week = '三';
                break;
            case 3:
                week = '四';
                break;
            case 4:
                week = '五';
                break;
            case 5:
                week = '六';
                break;
            case 6:
                week = '日';
                break;
            default:
                break;
        }
        return week;
    }
    // 数组对象去重
    function unCommon(obj){
        var uniques = [];
        var stringify = {};
        for (var i = 0; i < obj.length; i++) {
            var keys = Object.keys(obj[i]);
            keys.sort(function(a, b) {
                return (Number(a) - Number(b));
            });
            var str = '';
            for (var j = 0; j < keys.length; j++) {
                str += JSON.stringify(keys[j]);
                str += JSON.stringify(obj[i][keys[j]]);
            }
            if (!stringify.hasOwnProperty(str)) {
                uniques.push(obj[i]);
                stringify[str] = true;
            }
        }
        return uniques;
    }
    // 对象数组按指定项排序
    function compare(property){
        return function(a,b){
            var value1 = a[property];
            var value2 = b[property];
            return value1 - value2;
        }
    }
</script>
</body>
</html>